home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / unix / lq-text / 2950 < prev    next >
Encoding:
Text File  |  1992-08-26  |  46.1 KB  |  1,529 lines

  1. #! /bin/sh
  2. : part 02
  3. echo x - lq-text/src/filters/Makefile 1>&2
  4. sed 's/^X//' >lq-text/src/filters/Makefile <<'@@@End of lq-text/src/filters/Makefile'
  5. X# filters/Makefile -- Copyright 1990 Liam R. Quin.  All Rights Reserved.
  6. X# This code is NOT in the public domain.
  7. X# See the file ../COPYRIGHT for full details.
  8. X
  9. X# This Makefile belongs in the "src/filters" directory.
  10. X#
  11. X# Note that most of the actual configuration is done in ../Makefile and
  12. X# in ../h/global.h, and not here.
  13. X
  14. X# $Id: Makefile,v 1.4 90/10/06 00:57:26 lee Rel $
  15. X
  16. X
  17. X# This is what gets made:
  18. XTARGETS = MailFilter NewsFilter
  19. XLIBFILES=$(TARGETS)
  20. XEXTRA=-DMAILFILTER='$(MAILFILTER)' -DNEWSFILTER='$(NEWSFILTER)' $(EXTRA)
  21. X
  22. XSRCS = FilterMain.c FilterType.c MailFilter.c NewsFilter.c
  23. XOBJS = FilterMain.o FilterType.o MailFilter.o NewsFilter.o
  24. X
  25. XPWD=filters
  26. X
  27. XDESTDIR=../lib
  28. XLQ=../lib/liblq.a
  29. XMODE=755
  30. X
  31. X# for compiling:
  32. XEXTRA=-I../h
  33. XRANLIB=echo
  34. X
  35. Xall: $(TARGETS)
  36. X
  37. Xsaber_src:
  38. X    echo $(PWD)
  39. X    #cd $(PWD)
  40. X    #load $(CFLAGS) $(SRCS)
  41. X    #cd ..
  42. X
  43. Xsaber_obj:
  44. X    #cd $(PWD)
  45. X    #load $(CFLAGS) $(SRCS)
  46. X    #cd ..
  47. X
  48. Xinstall: all
  49. X    for i in $(LIBFILES); do cp "$$i" $(DESTDIR); \
  50. X    strip "$(DESTDIR)/$$i" ; \
  51. X    chmod $(MODE) "$(DESTDIR)/$$i" ; \
  52. X    done
  53. X
  54. Xtidy:
  55. X    /bin/rm -f *.o core m.log tags
  56. X
  57. Xclean: tidy
  58. X    /bin/rm -f $(TARGETS) $(TEST)
  59. X
  60. Xdepend:
  61. X    mkdep $(CFLAGS) *.c
  62. X
  63. XCFilter: FilterMain.o CFilter.o
  64. X    $(CC) $(CFLAGS) -o CFilter FilterMain.o CFilter.o $(MALLOC) $(LQ)
  65. X
  66. XNewsFilter: FilterMain.o NewsFilter.o
  67. X    $(CC) $(CFLAGS) -o NewsFilter FilterMain.o NewsFilter.o $(MALLOC) $(LQ)
  68. X
  69. XMailFilter: FilterMain.o MailFilter.o
  70. X    $(CC) $(CFLAGS) -o MailFilter FilterMain.o MailFilter.o $(MALLOC) $(LQ)
  71. X
  72. XCDMSFilter: FilterMain.o CDMSFilter.o
  73. X    $(CC) $(CFLAGS) -o CDMSFilter FilterMain.o CDMSFilter.o $(MALLOC) $(LQ)
  74. X
  75. X#
  76. X# $Log:    Makefile,v $
  77. X# Revision 1.4  90/10/06  00:57:26  lee
  78. X# Prepared for first beta release.
  79. X# 
  80. X# Revision 1.3  90/10/03  21:14:45  lee
  81. X# Added MAILFILTER stuff.
  82. X# 
  83. X# Revision 1.2  90/09/28  21:54:43  lee
  84. X# No longer uses OWNER.
  85. X# 
  86. X# Revision 1.1  90/08/09  19:17:58  lee
  87. X# Initial revision
  88. X# DO NOT PUT ANYTHING AFTER THIS LINE
  89. X# DO NOT DELETE THIS LINE -- mkdep uses it.
  90. X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
  91. X
  92. XFilterMain.o: FilterMain.c
  93. XMailFilter.o: MailFilter.c /usr/include/malloc.h
  94. XMailFilter.o: ../h/wordrules.h ../h/emalloc.h
  95. XNewsFilter.o: NewsFilter.c 
  96. XNewsFilter.o: ../h/wordrules.h ../h/emalloc.h
  97. XTroffFilter.o: TroffFilter.c 
  98. XTroffFilter.o: ../h/wordrules.h ../h/emalloc.h
  99. X
  100. X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
  101. @@@End of lq-text/src/filters/Makefile
  102. echo x - lq-text/src/filters/NewsFilter.c 1>&2
  103. sed 's/^X//' >lq-text/src/filters/NewsFilter.c <<'@@@End of lq-text/src/filters/NewsFilter.c'
  104. X/* NewsFilter.c -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  105. X * This code is NOT in the public domain.
  106. X * See the file COPYRIGHT for full details.
  107. X */
  108. X
  109. X/* $Id: NewsFilter.c,v 1.5 90/10/06 00:57:27 lee Rel1-10 $
  110. X */
  111. X
  112. X/* Filter for usenet articles.
  113. X * Throw away all of the header except
  114. X * Subject
  115. X * From
  116. X * Organi[sz]ation
  117. X *
  118. X * Probably ought to keep Message-ID, but I can't store it anyway!
  119. X *
  120. X * See FilterMain and wordrules.h for more info.
  121. X *
  122. X */
  123. X
  124. X#ifdef SYSV
  125. X extern int _filbuf(), _flsbuf(); /* for lint! */
  126. X#endif
  127. X#include <stdio.h>
  128. X#include <malloc.h>
  129. X#include <ctype.h>
  130. X#include "wordrules.h"
  131. X
  132. X#include "emalloc.h"
  133. X
  134. X#define STREQ(boy, girl) ((*(boy) == *(girl)) && !strcmp(boy, girl))
  135. X
  136. X/** C Library functions that need to be declared: **/
  137. X#ifndef tolower
  138. X extern int tolower();
  139. X#endif
  140. Xextern int strcmp();
  141. X/** Functions in this file that need to be declared **/
  142. Xint GetChar();
  143. Xvoid Header(), Body();
  144. X/** **/
  145. X
  146. Xextern char *progname;
  147. Xvoid Filter();
  148. X
  149. Xchar *KeepThese[] = { /* these must be sorted on the first character */
  150. X    "from",
  151. X    "keywords",
  152. X    "summary",
  153. X    "subject",
  154. X    "organisation",
  155. X    "organization",
  156. X    0
  157. X};
  158. X
  159. Xint icstreq(s1, s2) /* case insensitive strcmp */
  160. X    char *s1, *s2;
  161. X{
  162. X    register char ch1, ch2;
  163. X
  164. X    while (*s1 && *s2) {
  165. X    if (*s1 != *s2) {
  166. X        if (isupper(*s1)) {
  167. X        ch1 = tolower(*s1);
  168. X        ch2 = (*s2);
  169. X        } else if (isupper(*s2)) {
  170. X        /* Note that we only have to test one character for case! */
  171. X        ch1 = (*s1);
  172. X        ch2 = tolower(*s2);
  173. X        } else {
  174. X        return 0; /* they are different */
  175. X        }
  176. X        if (ch1 != ch2) return 0; /* the strings differ */
  177. X    }
  178. X    s1++; s2++;
  179. X    }
  180. X    if (!*s1 && !*s2) {
  181. X    return 1; /* they are the same */
  182. X    }
  183. X    return 0; /* they are different */
  184. X}
  185. X
  186. Xint
  187. XIsWanted(String)
  188. X    char *String;
  189. X{
  190. X    char **p;
  191. X    int ch = String[0];
  192. X
  193. X    if (isupper(ch)) ch = tolower(ch);
  194. X
  195. X    for (p = KeepThese; *p && **p; p++) {
  196. X    if (ch < **p) return 0; /* gone too far */
  197. X     else if (icstreq(String, *p)) return 1;
  198. X    }
  199. X    return 0;
  200. X}
  201. X
  202. Xvoid
  203. XFilter(InputFile, Name)
  204. X    FILE *InputFile;
  205. X    char *Name;
  206. X{
  207. X    Header(InputFile, Name);
  208. X    Body(InputFile, Name);
  209. X}
  210. X
  211. Xtypedef enum {
  212. X    F_NotSeenAnythingYet,
  213. X    F_InTheFirstWord,
  214. X    F_AfterTheFirstWord
  215. X} t_FirstWord;
  216. X
  217. Xint InWord = 0;
  218. X
  219. Xvoid
  220. XHeader(InputFile, Name)
  221. X    FILE *InputFile;
  222. X    char *Name;
  223. X{
  224. X    int AtStartOfLine = 1;
  225. X    int IgnoreLine = 1; /* initialised for lint and gcc -W really... */
  226. X    t_FirstWord FirstWord = F_NotSeenAnythingYet;
  227. X    int ch;
  228. X    static int BufLen;
  229. X    static char *Buffer = 0;
  230. X    int AtStartOfWord;
  231. X    register char *q;
  232. X
  233. X    if (Buffer == 0) {
  234. X    BufLen = 24;
  235. X    Buffer = emalloc(BufLen);
  236. X    }
  237. X
  238. X    q = Buffer;
  239. X    InWord = 0;
  240. X
  241. X    while ((ch = GetChar(InputFile)) != EOF) {
  242. X    if (ch == '\n') {
  243. X        if (AtStartOfLine) { /* a blank line */
  244. X        putchar('\n');
  245. X        return;
  246. X        }
  247. X    }
  248. X
  249. X    InWord = InWord ? WithinWord(ch) : StartsWord(ch);
  250. X
  251. X    switch (FirstWord) {
  252. X    case F_NotSeenAnythingYet:
  253. X        if (InWord) {
  254. X        FirstWord = F_InTheFirstWord;
  255. X        if (q - Buffer >= BufLen - 1) {
  256. X            int where = q - Buffer;
  257. X
  258. X            BufLen += 24;
  259. X            Buffer = erealloc(Buffer, BufLen);
  260. X            q = &Buffer[where];
  261. X        }
  262. X        *q++ = ch;
  263. X        } else {
  264. X        putchar(' ');
  265. X        }
  266. X        break;
  267. X    case F_InTheFirstWord:
  268. X        if (InWord) {
  269. X        if (q - Buffer >= BufLen - 1) {
  270. X            int where = q - Buffer;
  271. X
  272. X            BufLen += 24;
  273. X            Buffer = erealloc(Buffer, BufLen += 24);
  274. X            q = &Buffer[where];
  275. X        }
  276. X        *q++ = ch;
  277. X        break;
  278. X        } else { /* reached the end of the first word on the line */
  279. X        *q = '\0';
  280. X        /* See if it's a keyword */
  281. X          if ((IgnoreLine = !IsWanted(Buffer)) != 0) {
  282. X            /* Turn the word into one that won't get indexed,
  283. X             * so that word counmts are unaffected:
  284. X             * We use qxxxxxxx (any number of x's) for this.
  285. X             */
  286. X            for (q = Buffer; *q; q++) {
  287. X            putchar((q == Buffer) ? 'q' : 'x');
  288. X            }
  289. X            putchar (ch == '\n' ? '\n' : ' ');
  290. X        } else {
  291. X            printf("%s%c", Buffer, ch == '\n' ? ch : ' ');
  292. X        }
  293. X        FirstWord = F_AfterTheFirstWord;
  294. X        }
  295. X        break;
  296. X    default:
  297. X        if ((AtStartOfLine = (ch == '\n'))) {
  298. X        IgnoreLine = 0;
  299. X        q = Buffer;
  300. X        FirstWord = F_NotSeenAnythingYet;
  301. X        AtStartOfWord = 1;
  302. X        }
  303. X        if (InWord && !IgnoreLine) {
  304. X        putchar(ch);
  305. X        } else {
  306. X        if (AtStartOfWord && InWord) {
  307. X            putchar('q');
  308. X            AtStartOfWord = 0;
  309. X        } else if (InWord) {
  310. X            putchar('x');
  311. X        } else if (isspace(ch)) {
  312. X            putchar(ch);
  313. X        } else {
  314. X            putchar(' ');
  315. X        }
  316. X        }
  317. X        if (!InWord) AtStartOfWord = 1;
  318. X    }
  319. X    if ((AtStartOfLine = (ch == '\n'))) {
  320. X        IgnoreLine = 0;
  321. X        q = Buffer;
  322. X        FirstWord = F_NotSeenAnythingYet;
  323. X        AtStartOfWord = 1;
  324. X    }
  325. X    }
  326. X    if (ch == EOF) {
  327. X    fprintf(stderr, "%s: warning: Mail folder %s has no message body\n",
  328. X            progname, Name);
  329. X    }
  330. X}
  331. X
  332. Xvoid
  333. XBody(InputFile, Name)
  334. X    FILE *InputFile;
  335. X    char *Name;
  336. X{
  337. X    int ch;
  338. X
  339. X    while ((ch = GetChar(InputFile)) != EOF) {
  340. X    if (InWord = InWord ? WithinWord(ch) : StartsWord(ch)) {
  341. X        putchar(ch);
  342. X    } else {
  343. X        putchar((ch == '\n') ? '\n' : ' ');
  344. X    }
  345. X    }
  346. X}
  347. X
  348. X#ifdef __GNU__
  349. Xinline
  350. X#endif
  351. Xint
  352. XGetChar(fd)
  353. X    FILE *fd;
  354. X{
  355. X    static int LastChar = 0;
  356. X
  357. X    if (LastChar) {
  358. X    int ch = LastChar;
  359. X    LastChar = 0;
  360. X    return ch;
  361. X    }
  362. X
  363. X    /* Only return a single quote if it is surrounded by letters */
  364. X    if ((LastChar = getc(fd)) == '\'') {
  365. X    LastChar = getc(fd);
  366. X    if (InWord && isalpha(LastChar)) return '\'';
  367. X    else return ' ';
  368. X    } else {
  369. X    int ch = LastChar;
  370. X    LastChar = 0;
  371. X    return ch;
  372. X    }
  373. X}
  374. X
  375. X/*
  376. X * $Log:    NewsFilter.c,v $
  377. X * Revision 1.5  90/10/06  00:57:27  lee
  378. X * Prepared for first beta release.
  379. X * 
  380. X * Revision 1.4  90/09/20  16:36:59  lee
  381. X * Fixed icstrcmp() and IsWanted() so that the unwanted parts of headers
  382. X * get deleted again.... (oops!)
  383. X * 
  384. X * Revision 1.3  90/09/19  21:19:50  lee
  385. X * Now supports turning unindexed stuff into qxxxxx-words.
  386. X * 
  387. X * Revision 1.2  90/08/29  21:56:58  lee
  388. X * Alpha release.
  389. X * 
  390. X * Revision 1.1  90/08/09  19:17:57  lee
  391. X * Initial revision
  392. X * 
  393. X * Revision 1.2  89/09/16  21:16:01  lee
  394. X * First demonstratable version.
  395. X * 
  396. X * Revision 1.1  89/09/07  21:05:48  lee
  397. X * Initial revision
  398. X * 
  399. X */
  400. @@@End of lq-text/src/filters/NewsFilter.c
  401. echo x - lq-text/src/h/Liamdbm.h 1>&2
  402. sed 's/^X//' >lq-text/src/h/Liamdbm.h <<'@@@End of lq-text/src/h/Liamdbm.h'
  403. X/* Liamdbm.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  404. X * This code is NOT in the public domain.
  405. X * See the file COPYRIGHT for full details.
  406. X */
  407. X
  408. X/* $Id: Liamdbm.h,v 1.2 90/10/06 02:18:14 lee Rel1-10 $
  409. X *
  410. X * This is used with gdbm.  I have not linked with gdbm, and, if you
  411. X * wish to do so, you must be careful not to voilate any copyright
  412. X * notices... (sigh)
  413. X *
  414. X * The version of gdbm for which I had a manual is rather old and had no
  415. X * ndbm compatibility.
  416. X */
  417. X
  418. X#include "gdbm.h"
  419. Xextern datum gdbm_fetch();
  420. Xextern datum gdbm_firstkey();
  421. Xextern datum gdbm_nextkey();
  422. X
  423. Xtypedef char DBM;
  424. X
  425. X#define dbm_store(db, key, data, mode) gdbm_store(db, key, data)
  426. X/* gdbm_open is stupder than ndbm_open.... */
  427. X#define dbm_open(FileName, Mode, m) gdbm_open(FileName, 512, Mode, 0)
  428. X#define dbm_fetch gdbm_fetch
  429. X#define dbm_close gdbm_close
  430. X#define dbm_firstkey gdbm_firstkey
  431. X#define dbm_nextkey gdbm_nextkey
  432. X
  433. X/*
  434. X * $Log:    Liamdbm.h,v $
  435. X * Revision 1.2  90/10/06  02:18:14  lee
  436. X * Prepared for first beta release.
  437. X * 
  438. X *
  439. X */
  440. @@@End of lq-text/src/h/Liamdbm.h
  441. echo x - lq-text/src/h/Revision.h 1>&2
  442. sed 's/^X//' >lq-text/src/h/Revision.h <<'@@@End of lq-text/src/h/Revision.h'
  443. X/* This header file gets updated with every distributed change to any source
  444. X * file anywhere in the lq-text package.
  445. X * A short description of the change is added to the Log here, too.
  446. X * Lee.
  447. X */
  448. X
  449. X#define LQTEXTREVISION "Release 1.10"
  450. X
  451. X/* $Revision: 1.10 $
  452. X *
  453. X * Revision 1.6  90/10/04  17:12:45  lee
  454. X * lqtext now compiles and mostly works under BSD.
  455. X * Fixes bug in phrase matching -- PhraseMatchLevel now works on one-word
  456. X * phrases.
  457. X * 
  458. X * Revision 1.5  90/09/28  22:19:36  lee
  459. X * Made GetChar() a macro in lqaddfile -- speed improvement...
  460. X * 
  461. X * Revision 1.4  90/09/20  16:37:35  lee
  462. X * Fixed Mail and News filters so that they throw away the unwanted header
  463. X * parts correctly.
  464. X * 
  465. X * Revision 1.3  90/09/20  12:51:24  lee
  466. X * Major sdbm initialisation bug fixed.
  467. X * 
  468. X * Revision 1.2  90/09/20  11:52:35  lee
  469. X * Fixed the filters so that lqshow highlights the right word (the qxx fix)
  470. X * 
  471. X * Revision 1.1  90/09/20  11:52:18  lee
  472. X * Initial revision
  473. X * 
  474. X *
  475. X */
  476. @@@End of lq-text/src/h/Revision.h
  477. echo x - lq-text/src/h/blkheader.h 1>&2
  478. sed 's/^X//' >lq-text/src/h/blkheader.h <<'@@@End of lq-text/src/h/blkheader.h'
  479. X/* blkheader.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  480. X * This code is NOT in the public domain.
  481. X * See the file COPYRIGHT for full details.
  482. X *
  483. X * (was called blockheader.h, but this was too long on SysV for RCS)
  484. X */
  485. X
  486. X/* descibe the physical WOrdPlace database...
  487. X *
  488. X * $Header: /usr/src/cmd/lq-text/src/h/RCS/blkheader.h,v 1.2 90/03/20 20:57:46 lee Rel1-10 $
  489. X *
  490. X * $Log:    blkheader.h,v $
  491. X * Revision 1.2  90/03/20  20:57:46  lee
  492. X * removed WID from the block.  This reduces checking, but should also
  493. X * noticeably reduce the size of the database.
  494. X * 
  495. X * Revision 1.1  90/03/20  20:54:44  lee
  496. X * Initial revision
  497. X *
  498. X */
  499. X
  500. X/* The header of each block -- I can't use sReadNumber, because I don't know
  501. X * the size of NextOffset until I get to the end, and it's too late by then!
  502. X *
  503. X * I should really store the block offset, and not the byte offset.  This
  504. X * would save a whole byte -- I could use 3 bytes for the NextBlock!
  505. X */
  506. Xtypedef struct {
  507. X    unsigned long NextOffset; /* a byte offset */
  508. X    char Data[1]; /* the address of this is where the number start... */
  509. X} t_BlockHeader;
  510. @@@End of lq-text/src/h/blkheader.h
  511. echo x - lq-text/src/h/emalloc.h 1>&2
  512. sed 's/^X//' >lq-text/src/h/emalloc.h <<'@@@End of lq-text/src/h/emalloc.h'
  513. X/* emalloc.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  514. X * This code is NOT in the public domain.
  515. X * See the file COPYRIGHT for full details.
  516. X */
  517. X
  518. X/* emalloc.h -- header file for emalloc.c, Liam Quin's malloc() wrapper
  519. X *
  520. X * $Id: emalloc.h,v 1.5 91/03/02 19:40:04 lee Rel1-10 $
  521. X *
  522. X * $Log:    emalloc.h,v $
  523. X * Revision 1.5  91/03/02  19:40:04  lee
  524. X * Simpler version of malloc defines if MALLOCTRACE unused...
  525. X * 
  526. X * Revision 1.4  91/03/02  18:31:21  lee
  527. X * Simpler call to malloc wrappers if MALLOCTRACE undefined.
  528. X * 
  529. X * Revision 1.3  90/10/06  02:18:26  lee
  530. X * Prepared for first beta release.
  531. X * 
  532. X * Revision 1.2  90/08/29  21:57:44  lee
  533. X * removed most of the testing code
  534. X * 
  535. X * Revision 1.1  90/08/09  19:14:48  lee
  536. X * Initial revision
  537. X * 
  538. X * Revision 2.2  89/10/08  20:45:20  lee
  539. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  540. X * 
  541. X *
  542. X */
  543. X
  544. Xextern int _LiamIsInCurses;
  545. X
  546. X#define InitScr() (_LiamIsInCurses = initscr())
  547. X#define EndWin() (_LiamIsInCurses ? (_LiamIsInCurses = 0), endwin() : 0)
  548. X
  549. Xextern char *_emalloc(), *_erealloc(), *_ecalloc();
  550. Xextern void _efree();
  551. X
  552. X#ifdef MALLOCTRACE
  553. X#define emalloc(u) _emalloc(u, __FILE__, __LINE__)
  554. X#define erealloc(s, u) _erealloc(s, u, __FILE__, __LINE__)
  555. X#define ecalloc(n, siz) _ecalloc(n, siz, __FILE__, __LINE__)
  556. X#define efree(s) _efree(s, __FILE__, __LINE__)
  557. X#else
  558. X#define emalloc _emalloc
  559. X#define erealloc _erealloc
  560. X#define ecalloc _ecalloc
  561. X#define efree _efree
  562. X#endif
  563. @@@End of lq-text/src/h/emalloc.h
  564. echo x - lq-text/src/h/fileinfo.h 1>&2
  565. sed 's/^X//' >lq-text/src/h/fileinfo.h <<'@@@End of lq-text/src/h/fileinfo.h'
  566. X/* fileinfo.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  567. X * This code is NOT in the public domain.
  568. X * See the file COPYRIGHT for full details.
  569. X */
  570. X
  571. X/* Internal structure used by NX-Text to represent a word */
  572. X
  573. X/* Needs: sys/types.h */
  574. X
  575. X/* $Id: fileinfo.h,v 1.2 90/10/06 02:18:27 lee Rel1-10 $
  576. X *
  577. X * $Log:    fileinfo.h,v $
  578. X * Revision 1.2  90/10/06  02:18:27  lee
  579. X * Prepared for first beta release.
  580. X * 
  581. X * Revision 1.1  90/08/09  19:14:57  lee
  582. X * Initial revision
  583. X * 
  584. X * Revision 2.2  89/10/08  20:45:57  lee
  585. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  586. X * 
  587. X * Revision 2.1  89/10/02  01:14:29  lee
  588. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  589. X * 
  590. X * Revision 1.2  89/09/16  21:15:19  lee
  591. X * First demonstratable version.
  592. X * 
  593. X * Revision 1.1  89/09/07  21:00:34  lee
  594. X * Initial revision
  595. X * 
  596. X *
  597. X */
  598. X
  599. Xtypedef unsigned long t_FID;
  600. X
  601. Xtypedef struct {
  602. X    char *Name;
  603. X    t_FID FID; /* File Identifier */
  604. X    int FilterType; /* command to ASCIIify, 0 unknown, 1 none */
  605. X    time_t Date; /* when the file was last indexed */
  606. X    FILE *Stream;
  607. X} t_FileInfo;
  608. X
  609. X#define FindFile(name) ((*(name) == '/') ? (name) : _FindFile(name))
  610. Xextern char *_FindFile();
  611. @@@End of lq-text/src/h/fileinfo.h
  612. echo x - lq-text/src/h/filter.h 1>&2
  613. sed 's/^X//' >lq-text/src/h/filter.h <<'@@@End of lq-text/src/h/filter.h'
  614. X/* filter.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  615. X * This code is NOT in the public domain.
  616. X * See the file COPYRIGHT for full details.
  617. X */
  618. X
  619. X/* filter.h -- define filter table for NX-Text, Liam Quin's text retrieval
  620. X * program.
  621. X * This table is built from a file like a simplified /etc/magic, normally
  622. X * stored in /usr/local/lib/nx-text/lib/filtertable
  623. X * but you can set this either here or in the Makefile.
  624. X *
  625. X * NEEDS: stdio.h
  626. X *
  627. X * $Id: filter.h,v 1.6 91/03/02 18:45:04 lee Rel1-10 $
  628. X *
  629. X * $Log:    filter.h,v $
  630. X * Revision 1.6  91/03/02  18:45:04  lee
  631. X * Spell MAILFILTER correctly in the ifdef...
  632. X * 
  633. X * Revision 1.5  90/10/13  03:11:31  lee
  634. X * Now defines filters for easier stand-alone testing of stuff...
  635. X * 
  636. X * Revision 1.4  90/10/06  02:18:28  lee
  637. X * Prepared for first beta release.
  638. X * 
  639. X * Revision 1.3  90/09/28  23:03:16  lee
  640. X * Now use MAILFILTER and NEWSFILTER...
  641. X * 
  642. X * Revision 1.2  90/08/29  21:57:57  lee
  643. X * removed most of the testing code
  644. X * 
  645. X * Revision 1.1  90/08/09  19:15:01  lee
  646. X * Initial revision
  647. X * 
  648. X * Revision 2.2  89/10/08  20:46:04  lee
  649. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  650. X * 
  651. X * Revision 2.1  89/10/02  01:14:33  lee
  652. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  653. X * 
  654. X *
  655. X */
  656. X
  657. X#define FTYPE_NEWS  1
  658. X#define FTYPE_MAIL  2
  659. X#define FTYPE_CDMS  3
  660. X#define FTYPE_MOSTLYASCII 4
  661. X#define FTYPE_C_SOURCE 5
  662. X
  663. X/* The Type field in each array entry is so that I can do some very simple
  664. X * checking...
  665. X */
  666. Xextern int fclose(), pclose();
  667. Xstruct s_FilterTable {
  668. X    int Type;
  669. X    int (* close)(); /* how to close the darned stream */
  670. X    char *String;
  671. X};
  672. X#ifndef FILTERDEF
  673. Xextern struct s_FilterTable FilterTable[];
  674. X#else
  675. Xstruct s_FilterTable FilterTable[] = {
  676. X    { 0, fclose, 0 }, /* use fopen() */
  677. X#ifndef NEWSFILTER
  678. X# define NEWSFILTER "NewsFilter"
  679. X#endif
  680. X    { FTYPE_NEWS, pclose, NEWSFILTER },
  681. X#ifndef MAILFILTER
  682. X# define MAILFILTER "MailFilter"
  683. X#endif
  684. X    { FTYPE_MAIL, pclose, MAILFILTER },
  685. X#ifdef FTYPE_CDMS /* CrystalWriter from Syntactics... */
  686. X    { FTYPE_CDMS, pclose, "CDMSFilter" },
  687. X#endif
  688. X#ifdef FTYPE_NTROFF
  689. X    { FTYPE_NTROFF, pclose, "lqderoff" }, /* not yet released, sorry */
  690. X#endif
  691. X    { FTYPE_MOSTLYASCII, pclose, "AsciiFilter" },
  692. X#ifdef FTYPE_C_SOURCE
  693. X    { FTYPE_C_SOURCE, pclose, "CFilter" }, /* leave me last! */
  694. X#endif
  695. X    /* If you add more, you MUST update MaxFilterType */
  696. X    { 0, 0, 0 }
  697. X};
  698. X#endif
  699. X#define MaxFilterType FTYPE_C_SOURCE
  700. @@@End of lq-text/src/h/filter.h
  701. echo x - lq-text/src/h/globals.h 1>&2
  702. sed 's/^X//' >lq-text/src/h/globals.h <<'@@@End of lq-text/src/h/globals.h'
  703. X/* globals.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  704. X * This code is NOT in the public domain.
  705. X * See the file COPYRIGHT for full details.
  706. X *
  707. X * $Id: globals.h,v 1.6 91/02/20 19:26:53 lee Rel1-10 $
  708. X *
  709. X * (see Log at end of this file for change history.  Keep this up to date
  710. X * using rcs if you have it...)
  711. X */
  712. X
  713. X/* globals.h -- declarations of globally accessible variables, and also
  714. X * of configurable parameters.
  715. X *
  716. X * Some of the configuation options might be given in ../Makefile, so
  717. X * you must check in there too.
  718. X *
  719. X * Everything that includes this file must be linked with Defaults.c
  720. X */
  721. X
  722. X/* 
  723. X * DOCPATH gives the list of directories in which to search in order
  724. X * to find files to retrieve and to index.  The default can be wired
  725. X * in here, or can be simply "." (in which case relative pathnames will
  726. X * be from wherever one invokes the commands, and absolute pathnames
  727. X * will be absolute.  For example,
  728. X * #define DFLTDOCPATH "/usr/man:."
  729. X * In any case, it can be overridden by a DOCPATH line in the configuration
  730. X * file for a given database (README in the database directory), and also
  731. X * by an environment variable DOCPATH (the latter taking precedence over
  732. X * the former).
  733. X *
  734. X * Use ((char *) 0) to disable the default -- in this case, you always have
  735. X * to give one, either with the $DOCPATH variable or in the database file.
  736. X *
  737. X */
  738. X#ifndef DFLTDOCPATH
  739. X# define DFLTDOCPATH ((char *) 0)
  740. X#endif
  741. X
  742. X/* LQTEXTDIR: if the programs can't find the directory to use -- i.e.,
  743. X * there was no -d option and $(LQTEXTDIR) is unset, we either
  744. X * look in UNDERHOME (if that was defined here) or in wherever LQTEXTDIR
  745. X * is defined to point.
  746. X */
  747. X#ifndef LQTEXTDIR
  748. X# define LQTEXTDIR "/usr/spool/lqtextdir"
  749. X#endif
  750. X
  751. X/* If UNDERHOME is set, look there for a directory -- e.g. 
  752. X * #define UNDERHOME "sockdrawer"
  753. X * would make lqtext programs look for a directory something like
  754. X * /users/liam/sockdrawer
  755. X * (where /users/liam is my login directory)
  756. X */
  757. X#ifndef UNDERHOME
  758. X# define UNDERHOME "LQTEXTDIR"
  759. X#endif
  760. X
  761. X/* The name of a configuration file found in the database directory:
  762. X */
  763. X#define CONFIGFILE "README"
  764. X
  765. X/* If the config file doesn't give a filename for a list of common
  766. X * words, we look for one called DFLTCOMMONFILE (and don't mind if we
  767. X * don't find it).  Use "/dev/null" or ((char *) 0) if you want to
  768. X * disable the default.
  769. X * It's case sensitive, of course.
  770. X */
  771. X#define DFLTCOMMONFILE "CommonWords"
  772. X
  773. X#ifndef PAGER
  774. X/* The default pager to use if the user doesn't set $PAGER.  This is only
  775. X * used in lqshow, the browser.  Good things to try are
  776. X * more, "less -Ce", and (generally only on System V) "pg -ns".
  777. X * Specify an absolute path if possible.  It's often a lot faster, and
  778. X * it's somewhat safer...
  779. X */
  780. X# ifdef BSD
  781. X#  define PAGER "/usr/ucb/more"
  782. X# else
  783. X#  define PAGER "/usr/bin/pg -ns"
  784. X# endif
  785. X#endif
  786. X
  787. X#ifndef DBMCREAT
  788. X/* If you are using dbm or gdbm (?), you will need to create the dbm files
  789. X * by hand yourself.  Defining DBMCREAT as 0 makes the software do this
  790. X * automatically, with a very slight performance penalty.
  791. X *
  792. X * ndbm and sdbm can use O_CREAT, so set it to 1 here for them.
  793. X * You will also have to look at ../Makefile, ../PORTING, smalldb.h and
  794. X * ../lqlib/smalldb.h, making whatever changes are needed.
  795. X */
  796. X# define DBMCREAT 1 /* 1 for ndbm, 0 for dbm */
  797. X#endif
  798. X
  799. X#ifdef sparc
  800. X# define NEEDALIGN
  801. X#endif
  802. X
  803. X#ifdef mips /* e.g. SGI machines */
  804. X# define NEEDALIGN
  805. X#endif
  806. X
  807. X/* NEEDALIGN is for C compilers that require C structures to start at
  808. X * word boundaries.  You need this on sparc and sgi machines...
  809. X */
  810. X
  811. X/***
  812. X *** If you want to change anything beyond here...
  813. X ***
  814. X *** well, you can.
  815. X *** After all, it's your copy.
  816. X ***
  817. X *** But don't come running back to me if it doesn't work!
  818. X *** At least not until you have tried
  819. X ***    +  understanding what the problem is;
  820. X ***    +  looking at the source to see why;
  821. X ***    +  fixing the problem;
  822. X ***    +  taking off your shoes and socks and grinning for a while.
  823. X ***
  824. X *** Liam.
  825. X ***
  826. X ***/
  827. X
  828. X/* The following let you reconfigure the names of the files that form
  829. X * part of the database, but there is no point in doing so unless you
  830. X * are porting to some strange system that has absurd filename restrictions!
  831. X */
  832. X#ifndef WORDINDEX
  833. X# define WORDINDEX "wordlist"
  834. X    /* This is a dbm file, so you'll get two files, one with ".pag"
  835. X     * stuck on the end and one with ".dir" on the end.
  836. X     * It contains an entry for every word in the database, enabling
  837. X     * the software to go from a word to an integer (well, a t_WID)
  838. X     * very quickly.
  839. X     * It tends to be a little over one tenth of the size of the DATABASE.
  840. X     */
  841. X#endif
  842. X#ifndef WIDINDEXFILE
  843. X# define WIDINDEXFILE "WIDIndex"
  844. X    /* WIDINDEXFILE contains each word in the datbase, together with some
  845. X     * information and the first few bytes of data.
  846. X     * It contains WIDBLOCKSIZE bytes for every word, but this has to
  847. X     * be at least MAXWORDLEN + 10 bytes long (see WordInfo.c).
  848. X     */
  849. X#endif
  850. X#ifndef DATABASE
  851. X# define DATABASE "data"
  852. X    /* For those words whose data doesn't fit into the first WIDBLOCKSIZE
  853. X     * bytes, space is allocated in this file in BLOCKSIZE chunks.  Make
  854. X     * BLOCKSIZE small, or you will waste a lot of space -- on the other
  855. X     * hand, there's a 4-byte-per-block overhead at the moment.
  856. X     * This file gets very  b  i  g  indeed.
  857. X     */
  858. X#endif
  859. X#ifndef FILEINDEX
  860. X# define FILEINDEX "FileList"
  861. X    /* This is a list of every file in the database, again in dbm format,
  862. X     * so there are actually two files (a .pag and a .dir) involved.
  863. X     * If your files are short, it will quickly grow to a tenth of the size
  864. X     * of the database.
  865. X     * It stores the filename, and some other information.
  866. X     */
  867. X#endif
  868. X#ifndef FIDFILE
  869. X# define FIDFILE "FIDFile"
  870. X    /* This contains the largest currently used file number... you can
  871. X     * look at it to see how many files have been indexed.
  872. X     * It is only a few bytes long.
  873. X     */
  874. X#endif
  875. X#ifndef WIDFILE
  876. X# define WIDFILE "WIDFile"
  877. X    /* This contains the largest currently used word number... you can
  878. X     * look at it to see how many unique words have been seen.
  879. X     * It is only a few bytes long.
  880. X     */
  881. X#endif
  882. X
  883. X#ifndef WIDBLOCKSIZE
  884. X# define WIDBLOCKSIZE    32
  885. X/* WIDBLOCKSIZE absolutely must be large enough to fit at least one byte
  886. X * of actual data, or all hell will break loose.
  887. X * (actually that could be fixed...).
  888. X * In any case, it has to contain (apart from the >= 1 byte of data):
  889. X * + the length count (1 byte) and the word itself (no null on the end)
  890. X * + the block number in the database (1..5 bytes)
  891. X * + the number of matches (1..5 bytes)
  892. X *
  893. X * It helps efficiency very, very slightly if these are a power of two
  894. X * bytes, as then they never cross Unix block boundaries.
  895. X *
  896. X */
  897. X#endif
  898. X
  899. X#ifndef BLOCKSIZE
  900. X#define BLOCKSIZE    64
  901. X/* BLOCKSIZE is the size of blocks in the data file.  There are several
  902. X * tradeoffs:
  903. X * + there is a 4-bytes-per-block overhead for list pointers, so it's
  904. X *   a good idea to make them large
  905. X * + there's a bit of work involved in fetching the blocks, so things go
  906. X *   faster if they're larger...
  907. X * + many blocks are not full, so it's a good idea to make them small.
  908. X *   On average, a little over (BLOCKSIZE - 4) / 2 bytes are wasted for
  909. X *   every word chain.
  910. X * + since many of the blocks are not full, it's a good idea to make them
  911. X *   small, minimising the amount of extra data that gets copied around by
  912. X *   the Unix kernel.  If the blocks are smaller it'll go faster...
  913. X *
  914. X * It helps efficiency very, very slightly if these are a power of two
  915. X * bytes, as then they never cross Unix block boundaries.
  916. X *
  917. X */
  918. X#endif
  919. X
  920. X/**** Some useful macros */
  921. X
  922. X/* STREQ(a,b) is much faster than strcmp() in the (common) case that the
  923. X * first character of the strings differ.
  924. X * It is due (as far as I know) to Henry Spencer, at the University of
  925. X * Toronto Zoology Dept.,
  926. X * utzoo!henry
  927. X */
  928. X#ifndef STREQ
  929. X# define STREQ(henry,utzoo) (*(henry) == *(utzoo) && !strcmp(henry, utzoo))
  930. X#endif
  931. X
  932. X/* Inline functions are functions that get expanded inline during
  933. X * compilation -- sort of like macros with real local arguments.
  934. X * Not all compilers support them.
  935. X */
  936. X#ifdef __GNUC__
  937. X#  define INLINE inline
  938. X#else
  939. X#  define INLINE /* not supported */
  940. X#endif
  941. X
  942. X#ifdef DefineThem
  943. X# define DECL(name, type, value)   type name = value
  944. X# define EXTERN /* just define them please */
  945. X#else
  946. X# define EXTERN extern /* declare but do not define */
  947. X# define DECL(name, type, value)   EXTERN type name
  948. X#endif
  949. X
  950. X/****/
  951. X
  952. X/* Now declare (or define) things: */
  953. X
  954. Xextern char *progname; /* from progname.c, for error messages */
  955. XDECL(CommonWordFile, char *, DFLTCOMMONFILE); 
  956. XDECL(DatabaseDir, char *, LQTEXTDIR); 
  957. XDECL(FileIndex, char *, FILEINDEX);
  958. XDECL(WordIndex, char *, WORDINDEX);
  959. XDECL(DataBase, char *, DATABASE);
  960. XDECL(FidFile, char *, FIDFILE);
  961. XDECL(WidFile, char *, WIDFILE);
  962. XDECL(WidIndexFile, char *, WIDINDEXFILE);
  963. XDECL(DocPath, char *, DFLTDOCPATH); 
  964. X
  965. X/*
  966. X * $Log:    globals.h,v $
  967. X * Revision 1.6  91/02/20  19:26:53  lee
  968. X * Added NEEDALIGN on mips systems
  969. X * (thanks to Mark Moraes, moraes@cs.toronto.edu)
  970. X * 
  971. X * Revision 1.5  90/10/07  20:41:20  lee
  972. X * Added NEEDALIGN for fussy architectures.
  973. X * 
  974. X * Revision 1.4  90/10/06  02:21:21  lee
  975. X * Prepared for first beta release.
  976. X * 
  977. X * Revision 1.3  90/10/03  21:31:54  lee
  978. X * Added definition of PAGER, which has moved here from lqshow.c
  979. X * 
  980. X * Revision 1.2  90/08/09  19:15:03  lee
  981. X * after BSD lint and saber-C
  982. X * 
  983. X * Revision 1.1  90/03/23  17:32:11  lee
  984. X * Initial revision
  985. X * 
  986. X *
  987. X */
  988. @@@End of lq-text/src/h/globals.h
  989. echo x - lq-text/src/h/numbers.h 1>&2
  990. sed 's/^X//' >lq-text/src/h/numbers.h <<'@@@End of lq-text/src/h/numbers.h'
  991. X/* numbers.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  992. X * This code is NOT in the public domain.
  993. X * See the file COPYRIGHT for full details.
  994. X */
  995. X
  996. X/* ReadNumber and WriteNumber take/return a long, using a compression
  997. X * algorithm to reduce the amount of data taken.
  998. X *
  999. X * They use (char *) pointers instead if prefixes with an s.
  1000. X *
  1001. X * $Id: numbers.h,v 1.3 90/10/06 02:18:30 lee Rel1-10 $
  1002. X *
  1003. X */
  1004. X
  1005. Xextern INLINE unsigned long fReadNumber();
  1006. Xextern INLINE unsigned long sReadNumber();
  1007. X
  1008. Xextern INLINE void fWriteNumber();
  1009. Xextern INLINE void sWriteNumber();
  1010. X
  1011. X/*
  1012. X * $Log:    numbers.h,v $
  1013. X * Revision 1.3  90/10/06  02:18:30  lee
  1014. X * Prepared for first beta release.
  1015. X * 
  1016. X * Revision 1.2  90/08/09  19:15:42  lee
  1017. X * after BSD lint and saber-C
  1018. X * 
  1019. X * Revision 1.1  90/04/19  19:27:04  lee
  1020. X * Initial revision
  1021. X * 
  1022. X * Revision 2.2  89/10/08  20:46:43  lee
  1023. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1024. X * 
  1025. X * Revision 1.2  89/09/16  21:15:40  lee
  1026. X * First demonstratable version.
  1027. X * 
  1028. X * Revision 1.1  89/09/07  21:06:02  lee
  1029. X * Initial revision
  1030. X * 
  1031. X */
  1032. @@@End of lq-text/src/h/numbers.h
  1033. echo x - lq-text/src/h/pblock.h 1>&2
  1034. sed 's/^X//' >lq-text/src/h/pblock.h <<'@@@End of lq-text/src/h/pblock.h'
  1035. X/* pblock.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1036. X * This code is NOT in the public domain.
  1037. X * See the file COPYRIGHT for full details.
  1038. X */
  1039. X
  1040. X#ifndef PBLOCK_H /* the matching endif is at the end of the file... */
  1041. X
  1042. X# define PBLOCK_H
  1043. X/* The physical Word Database...
  1044. X *
  1045. X * First, there is the WID (from 1 to 4 bytes)
  1046. X *
  1047. X * Then, there is a NEXT pointer (or 0).
  1048. X *
  1049. X * Then, there is a list of (FID, OFFSET) pairs.
  1050. X *
  1051. X * $Header: /usr/src/cmd/lq-text/src/h/RCS/pblock.h,v 1.2 90/08/09 19:15:45 lee Rel1-10 $
  1052. X *
  1053. X * $Log:    pblock.h,v $
  1054. X * Revision 1.2  90/08/09  19:15:45  lee
  1055. X * after BSD lint and saber-C
  1056. X * 
  1057. X * Revision 1.1  90/03/01  23:54:37  lee
  1058. X * Initial revision
  1059. X * 
  1060. X * Revision 2.2  89/10/08  20:47:04  lee
  1061. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1062. X * 
  1063. X * Revision 2.1  89/10/02  01:15:36  lee
  1064. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1065. X * 
  1066. X * Revision 1.2  89/09/16  21:15:43  lee
  1067. X * First demonstratable version.
  1068. X * 
  1069. X * Revision 1.1  89/09/07  21:06:09  lee
  1070. X * Initial revision
  1071. X * 
  1072. X *
  1073. X */
  1074. X
  1075. Xtypedef struct {
  1076. X    t_FID FID;
  1077. X    unsigned long BlockInFile;
  1078. X    unsigned short WordInBlock;
  1079. X    unsigned short Flags;
  1080. X    unsigned char StuffBefore; /* preceding ignored garbage */
  1081. X} t_WordPlace;
  1082. X
  1083. X/* This structure is really only used by addfile; elsewhere arrays of
  1084. X * WordlPlace are used.
  1085. X */
  1086. X
  1087. Xtypedef struct s_WordPlaceList {
  1088. X    char *Word;
  1089. X    t_WordPlace WordPlace;
  1090. X    struct s_WordPlaceList *Next;
  1091. X} t_WordPlaceList;
  1092. X
  1093. X/* Warning: One cannot use structure copy for a pblock! */
  1094. X
  1095. X/* This does *NOT* correspond to the physical disk layout -- see pblock.c */
  1096. Xtypedef struct {
  1097. X    t_WID WID; /* for checking; */
  1098. X    unsigned long ChainStart;
  1099. X    unsigned long NumberOfWordPlaces;
  1100. X    t_WordPlace WordPlaces[1]; /* made by joining lots of disk blocks... */
  1101. X} t_pblock;
  1102. X
  1103. X#endif
  1104. @@@End of lq-text/src/h/pblock.h
  1105. echo x - lq-text/src/h/phrase.h 1>&2
  1106. sed 's/^X//' >lq-text/src/h/phrase.h <<'@@@End of lq-text/src/h/phrase.h'
  1107. X/* phrase.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1108. X * This code is NOT in the public domain.
  1109. X * See the file COPYRIGHT for full details.
  1110. X */
  1111. X
  1112. X/* LQ-Text -- Liam's Text Retrieval Package
  1113. X * Liam R. Quin, September 1989, and later...
  1114. X *
  1115. X * phrase.h -- data structures for handling entire phrases
  1116. X *
  1117. X */
  1118. X
  1119. X/* $Id: phrase.h,v 1.2 90/10/06 02:18:33 lee Rel1-10 $
  1120. X *
  1121. X */
  1122. X
  1123. X/* Represent a Phrase as a linked list of WordInfo pointers, plus a list
  1124. X * of matches.
  1125. X */
  1126. X
  1127. Xtypedef struct s_PhraseItem {
  1128. X    t_WordInfo *Word;
  1129. X    struct s_PhraseItem *Next;
  1130. X    unsigned long SearchIndex; /* For phrase-matching */
  1131. X    char *WordStart; /* pointer into original phrase */
  1132. X} t_PhraseItem;
  1133. X
  1134. Xtypedef enum {
  1135. X    PCM_AnyCase, /* Ignore case entirely */
  1136. X    PCM_HalfCase, /* Upper only matches upper; lower matches either */
  1137. X    PCM_SameCase, /* Exact matching */
  1138. X} t_PhraseCaseMatch;
  1139. X
  1140. Xtypedef struct s_Match {
  1141. X    t_WID WID;
  1142. X    t_WordPlace *Where;
  1143. X    struct s_Match *Next;
  1144. X} t_Match;
  1145. X
  1146. Xtypedef struct s_MatchList {
  1147. X    t_Match *Match;
  1148. X    struct s_MatchList *Next;
  1149. X} t_MatchList;
  1150. X
  1151. X
  1152. Xtypedef struct s_Phrase {
  1153. X    t_PhraseItem *Words; /* list of words and pblocks */
  1154. X    char *OriginalString; /* as supplied by the user */
  1155. X    char *ModifiedString; /* after deleting short/unindexed words */
  1156. X    unsigned long NumberOfMatches;
  1157. X    t_MatchList *Matches;
  1158. X    struct s_Phrase *Next; /* for use when we're in a list of phrases... */
  1159. X    unsigned short HasUnknownWords;
  1160. X} t_Phrase;
  1161. X
  1162. X/* This is for FilleList() */
  1163. Xtypedef struct s_Answer {
  1164. X    char *Answer;
  1165. X    struct s_Answer *Next;
  1166. X} t_Answer;
  1167. X
  1168. X/*
  1169. X * $Log:    phrase.h,v $
  1170. X * Revision 1.2  90/10/06  02:18:33  lee
  1171. X * Prepared for first beta release.
  1172. X * 
  1173. X * Revision 1.1  90/08/09  19:15:49  lee
  1174. X * Initial revision
  1175. X * 
  1176. X * Revision 1.1  89/09/17  23:03:37  lee
  1177. X * Initial revision
  1178. X * 
  1179. X */
  1180. @@@End of lq-text/src/h/phrase.h
  1181. echo x - lq-text/src/h/smalldb.h 1>&2
  1182. sed 's/^X//' >lq-text/src/h/smalldb.h <<'@@@End of lq-text/src/h/smalldb.h'
  1183. X/* smalldb.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1184. X * This code is NOT in the public domain.
  1185. X * See the file COPYRIGHT for full details.
  1186. X */
  1187. X
  1188. X/* $Id: smalldb.h,v 1.3 91/03/03 00:12:56 lee Exp $
  1189. X */
  1190. X
  1191. X/* You must include fcntl.h before this file. */
  1192. X
  1193. X#ifdef ndbm
  1194. X# include <ndbm.h>
  1195. X# define FoundDbmOK
  1196. X# define NDBM
  1197. X#endif
  1198. X
  1199. X#ifdef sdbm
  1200. X# include "sdbm.h"
  1201. X# define FoundDbmOK
  1202. X# define NDBM /* it's compatible */
  1203. X#endif
  1204. X
  1205. X#ifdef ozmahash
  1206. X# include "ozmadbm.h"
  1207. X# define FoundDbmOK
  1208. X# define NDBM /* it's compatible as well... */
  1209. X#endif
  1210. X
  1211. X#ifndef FoundDbmOK
  1212. X# include "Liamdbm.h"
  1213. X#endif
  1214. X
  1215. X#ifndef O_RDWR
  1216. X# include <fcntl.h>
  1217. X#endif
  1218. X
  1219. X#define CACHE 2 /* size of DBM cache in startdb() -- I only use two! */
  1220. X/* If you rip out the dbm cache stuff for use elsewhere, increse the 2
  1221. X * to something like 5 or so!!!  Each entry uses two file pointers.
  1222. X * Lee
  1223. X */
  1224. X
  1225. X#ifndef CACHE
  1226. X# define startdb(FilePrefix) dbm_open(FilePrefix, O_RDWR|O_CREAT, 0640)
  1227. X# define enddb(db) { if (db) dbm_close(db); }
  1228. X#endif
  1229. X
  1230. X
  1231. X#ifndef startdb
  1232. XDBM *startdb();
  1233. X#endif
  1234. X
  1235. X#ifndef enddb
  1236. X# ifdef CACHE
  1237. X#  define enddb(db) /* nothing to do, because of the cache */
  1238. X# else
  1239. X   void enddb();
  1240. X# endif /* CACHE */
  1241. X#endif /* !enddb */
  1242. X
  1243. X/*
  1244. X * $Log:    smalldb.h,v $
  1245. X * Revision 1.3  91/03/03  00:12:56  lee
  1246. X * Integrated ozmahash.
  1247. X * 
  1248. X * Revision 1.2  90/10/06  02:18:36  lee
  1249. X * Prepared for first beta release.
  1250. X * 
  1251. X * Revision 1.1  90/08/09  19:16:00  lee
  1252. X * Initial revision
  1253. X * 
  1254. X * Revision 2.2  89/10/08  20:47:19  lee
  1255. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1256. X * 
  1257. X * Revision 2.1  89/10/02  01:16:01  lee
  1258. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1259. X * 
  1260. X * Revision 1.2  89/09/16  21:15:45  lee
  1261. X * First demonstratable version.
  1262. X * 
  1263. X * Revision 1.1  89/09/07  21:06:12  lee
  1264. X * Initial revision
  1265. X * 
  1266. X */
  1267. @@@End of lq-text/src/h/smalldb.h
  1268. echo x - lq-text/src/h/wordindex.h 1>&2
  1269. sed 's/^X//' >lq-text/src/h/wordindex.h <<'@@@End of lq-text/src/h/wordindex.h'
  1270. X/* wordindex.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1271. X * This code is NOT in the public domain.
  1272. X * See the file COPYRIGHT for full details.
  1273. X */
  1274. X
  1275. X/* (this file is currently empty, but might return...) */
  1276. X
  1277. X/*
  1278. X * $Id: wordindex.h,v 1.2 90/10/06 02:18:38 lee Rel1-10 $
  1279. X *
  1280. X * $Log:    wordindex.h,v $
  1281. X * Revision 1.2  90/10/06  02:18:38  lee
  1282. X * Prepared for first beta release.
  1283. X * 
  1284. X * Revision 1.1  90/08/09  19:16:02  lee
  1285. X * Initial revision
  1286. X * 
  1287. X * Revision 2.1  89/10/02  01:16:06  lee
  1288. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1289. X * 
  1290. X * Revision 1.2  89/09/16  21:15:47  lee
  1291. X * First demonstratable version.
  1292. X * 
  1293. X * Revision 1.1  89/09/07  21:06:13  lee
  1294. X * Initial revision
  1295. X * 
  1296. X *
  1297. X */
  1298. @@@End of lq-text/src/h/wordindex.h
  1299. echo x - lq-text/src/h/wordinfo.h 1>&2
  1300. sed 's/^X//' >lq-text/src/h/wordinfo.h <<'@@@End of lq-text/src/h/wordinfo.h'
  1301. X/* wordinfo.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1302. X * This code is NOT in the public domain.
  1303. X * See the file COPYRIGHT for full details.
  1304. X */
  1305. X
  1306. X/*
  1307. X * $Id: wordinfo.h,v 1.3 90/10/06 02:21:30 lee Rel1-10 $
  1308. X */
  1309. X
  1310. Xtypedef unsigned long t_WID;
  1311. X
  1312. X#ifndef PBLOCK_H
  1313. X# include "pblock.h"
  1314. X#endif
  1315. X
  1316. X#ifndef WIDBLOCKSIZE
  1317. X#define WIDBLOCKSIZE 32
  1318. X#endif
  1319. X
  1320. Xextern char *WidIndexFile; /* Default.c */
  1321. X
  1322. X/* this is a hack for speed: */
  1323. X#define GetNextWID SpoofGetNextWID
  1324. X
  1325. X/** A t_WordInfo describes a single word, in terms of
  1326. X ** where it came from
  1327. X ** how to find its database entries
  1328. X ** how to find the in-core database entries (a copy of the above)
  1329. X **/
  1330. X
  1331. X/* There would be a performance benefit if this struct was smaller.
  1332. X * It was foolish of me to use WordInfo for so many different things in
  1333. X * addfile, and now I pay the price.
  1334. X * Addfile may end up calling malloc for 10,000 of these things...
  1335. X *
  1336. X * There should be:
  1337. X * t_WordPlace (exists, pblock.h)
  1338. X *    for recording a specific occurrence of a given word in a given file
  1339. X * t_WordInfo (definition follows... look down...)
  1340. X *    for recording information about a WID's entry in the database
  1341. X * t_WordPlaceList
  1342. X *    for addfile to make a list of word places...
  1343. X * t_pblock (exists, see pblock.h)
  1344. X *    for containing the list of WordPlaces found in the database for a
  1345. X *    given word, or for putting them there.  Uses arrays rather than
  1346. X *    lists to squeeze a few extra milliseconds.  Some hope :-( :-)
  1347. X *
  1348. X * t_WordPlaceList almost certainly happen in the next major edit phase...
  1349. X * t_WordInfo will then be somewhat smaller.
  1350. X * All of the entries marked with a leading comment (below) should
  1351. X * be elsewhere (and some of them were, in the Grand Design!).
  1352. X *
  1353. X */
  1354. Xtypedef struct s_WordInfo {
  1355. X    char *Word;
  1356. X    t_WID WID; /* My Word Identifier */
  1357. X    unsigned long NumberOfWordPlaces; /* total */
  1358. X    t_FID FID; /* where we got it from */
  1359. X    unsigned long Offset; /* word entry position in the data base */
  1360. X    struct s_WordInfo *Next; /* for making lists of WordInfo structs */
  1361. X    char *DataBlock; /* for writing me out to the index */
  1362. X    char *WordPlaceStart;
  1363. X    t_WordPlace *WordPlaces; /* first few pairs */
  1364. X    t_WordPlace WordPlace; /* For addfile -- this is due to go!!!! */
  1365. X    /* shorts are at the end to obviate alignment padding... */
  1366. X    unsigned long WordPlacesInHere;
  1367. X    unsigned short Length; /* Word length; reduce the need for strlen */
  1368. X#if 0
  1369. X    unsigned char Flags;
  1370. X    /* Flags serve two purposes:
  1371. X     * the LSB says whether the entry is sorted.
  1372. X     * the remainder are a logical AND of all entries in a sorted
  1373. X     * block.  NOTE: if the block is unsorted, the other bits should
  1374. X     * still be up to date.
  1375. X     */
  1376. X#endif
  1377. X} t_WordInfo;
  1378. X
  1379. X/*
  1380. X * $Log:    wordinfo.h,v $
  1381. X * Revision 1.3  90/10/06  02:21:30  lee
  1382. X * Prepared for first beta release.
  1383. X * 
  1384. X * Revision 1.2  90/08/09  19:16:04  lee
  1385. X * after BSD lint and saber-C
  1386. X * 
  1387. X * Revision 2.2  89/10/08  20:47:27  lee
  1388. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1389. X * 
  1390. X * Revision 2.1  89/10/02  01:16:15  lee
  1391. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1392. X * 
  1393. X * Revision 1.3  89/09/17  23:04:52  lee
  1394. X * Various fixes; NumberInBlock now a short...
  1395. X * 
  1396. X * Revision 1.2  89/09/16  21:15:49  lee
  1397. X * First demonstratable version.
  1398. X * 
  1399. X * Revision 1.1  89/09/07  21:06:16  lee
  1400. X * Initial revision
  1401. X * 
  1402. X */
  1403. @@@End of lq-text/src/h/wordinfo.h
  1404. echo x - lq-text/src/h/wordrules.h 1>&2
  1405. sed 's/^X//' >lq-text/src/h/wordrules.h <<'@@@End of lq-text/src/h/wordrules.h'
  1406. X/* wordrules.h -- Copyright 1989 Liam R. Quin.  All Rights Reserved.
  1407. X * This code is NOT in the public domain.
  1408. X * See the file COPYRIGHT for full details.
  1409. X */
  1410. X
  1411. X/* $Id: wordrules.h,v 1.2 90/10/06 02:18:39 lee Rel1-10 $
  1412. X *
  1413. X */
  1414. X
  1415. X/* Rules for determining what an indexable word looks like;
  1416. X * These are implemented by the various filters, as well as by
  1417. X * the indexing software itself.  This means that the filters
  1418. X * don't need to keep track of word lengths, as addfile will do this,
  1419. X * but that they should not emit non-word stuff if they can help it,
  1420. X * turning it into the equivalent amount (in bytes) of white-space
  1421. X * instead.
  1422. X * They should also turn words they don't want indexed into "qxxx",
  1423. X * with the right number of x's (e.g. "bare" --> "qxxx").
  1424. X */
  1425. X
  1426. X/* A "word" is a letter followed by any combination of
  1427. X * letters, digits or '_'.  An embedded (not trailing) ' is also allowed
  1428. X * (_ is allowed so that one can index progamming languages; strictly
  1429. X * speaking, a lot of languages allow _ at the start too, but I don't
  1430. X * want to get confused by nroff output etc., which contains lines of
  1431. X * underscores)
  1432. X *
  1433. X * This scheme currently excludes numbers...
  1434. X * 31, 31.4 and 31.9e4 will all be ignored.  So will 1987.
  1435. X */
  1436. X
  1437. X#define StartsWord(ch) isalpha(ch)
  1438. X#define WithinWord(ch) (isalnum(ch) || (ch == '_') || (ch == '\''))
  1439. X#define EndsWord(ch) isalnum(ch)
  1440. X
  1441. X/* Don't index words unless they are at least MinWordLength characters
  1442. X * long!
  1443. X */
  1444. X#define MinWordLength 3
  1445. X#define MaxWordLength 18 /* truncate words to this */
  1446. X/* The Following is for *.WordPlace.BlockInFile.  If words are constrained
  1447. X * to be 3 or more characters long, there can be at most
  1448. X * (FileBlockSize / 4) of them in a block (since words must be separated
  1449. X * by at least one character).
  1450. X * Hence, 7 bits, which allows 0..127 giving 128  distinct values,
  1451. X * gives us a block that is 128 * (MinWordLength + 1) bytes long.
  1452. X */
  1453. X#define FileBlockSize (128 * (MinWordLength + 1))
  1454. X
  1455. X/* WordPlace Flags:
  1456. X * When a plural word is found, or a possessive word, it is reduced to
  1457. X * being singular, and flags are set appropriately.
  1458. X * Also, a flag is set to say if the word started with a Capital Letter.
  1459. X * This puts Window, windows, and Window's all together, but enables them
  1460. X * to be differentiated for searching if required.
  1461. X * These flags are implemented by WordInfo and addfile, not by the various
  1462. X * filters, but the filters must preserve capitalisation of the first letter
  1463. X * in each word, and pass through apostrophes within words (like this's).
  1464. X */
  1465. X
  1466. X#define WPF_WASPLURAL        0001 /* The word...  ended in s */
  1467. X#define WPF_UPPERCASE        0002 /* ...Started with a capital letter */
  1468. X#define WPF_POSSESSIVE        0004 /* ...ended in 's */
  1469. X#define WPF_ENDEDINING        0010 /* ...ended in ing */
  1470. X#define WPF_LASTWASCOMMON    0020 /* the previous word was common */
  1471. X#define WPF_LASTHADLETTERS    0040 /* we skipped some letters to get here */
  1472. X#define WPF_HASSTUFFBEFORE    0100 /* Other than 1 byte of garbage before */
  1473. X#define WPF_LASTINBLOCK        0200 /* I'm the last word in this block */
  1474. X
  1475. X/* new note (jan 90):
  1476. X * You can't currently have both plural and posessive in the most common case
  1477. X * of the boys' muddy feet (for example), as the trailing ' gets deleted.
  1478. X * this doesn't matter, but perhaps that combination should be reserved for
  1479. X * had-another-standard-ending??? e.g. -ed or -ing, that isn't often followed by
  1480. X * -s or -'s...
  1481. X *
  1482. X * Also, ENDEDINING (ended in "ing") is currently unused entirely.
  1483. X * Perhaps if it is set, the plural and possessive bits should index which of
  1484. X * four endings was found, although this would preclude special-casing of the
  1485. X * s's combination.  Probably better that way.
  1486. X *
  1487. X * I should very much like to have another flag or two, perhaps embedded in
  1488. X * one of the other fields.  This might be feasible if there is a pre-scan
  1489. X * when the index is written to determine the most common (modal) flags and
  1490. X * distance (currently I assume 1) and to omit these whenever they are the default.
  1491. X * In this case, the fact that every occurrence of Jesus starts with a capital
  1492. X * letter (and ends in -s, *blush*), can still lead to most of the flags being
  1493. X * omitted.
  1494. X *
  1495. X * The next revision will separate the list of FIDs from the rest of the information,
  1496. X * in which case the embedding of the flags becomes a little trickier.  This
  1497. X * belongs in the TODO file now, sorry.
  1498. X *
  1499. X * Liam Quin, January 22nd 1990, at home in Warrington, England (ugh)
  1500. X *
  1501. X */
  1502. X
  1503. X/*
  1504. X * $Log:    wordrules.h,v $
  1505. X * Revision 1.2  90/10/06  02:18:39  lee
  1506. X * Prepared for first beta release.
  1507. X * 
  1508. X * Revision 1.1  90/08/09  19:16:05  lee
  1509. X * Initial revision
  1510. X * 
  1511. X * Revision 2.2  89/10/08  20:47:35  lee
  1512. X * Working version of nx-text engine.  Addfile and wordinfo work OK.
  1513. X * 
  1514. X * Revision 2.1  89/10/02  01:16:19  lee
  1515. X * New index format, with Block/WordInBlock/Flags/BytesSkipped info.
  1516. X * 
  1517. X * Revision 1.2  89/09/16  21:15:52  lee
  1518. X * First demonstratable version.
  1519. X * 
  1520. X * Revision 1.1  89/09/07  21:06:17  lee
  1521. X * Initial revision
  1522. X * 
  1523. X */
  1524. @@@End of lq-text/src/h/wordrules.h
  1525. echo end of part 02
  1526. -- 
  1527. Liam R. E. Quin,  lee@sq.com, SoftQuad Inc., Toronto, +1 (416) 963-8337
  1528.